<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        class Queue {
            item;
            constructor() {
                this.item = []
            }

            enqueue(val) {
                return this.item.push(val)
            }
            dequeue() {
                
                return this.item.shift()
            }
            front() {
                return this.item[0]
            }
            isEmpty() {
                return this.item.length === 0
            }
            size() {
                return this.item.length
            }
            toString() {
                let str = ''
                for (let i = 0; i < this.item.length; i++) {
                    str += this.item[i] + ' '
                }
                return str
            }
        }

        // let q = new Queue()
        // q.enqueue(10)
        // q.enqueue(11)
        // q.enqueue(12)
        // q.enqueue(13)
        // console.log(q)
        // q.dequeue()
        // console.log(q)
        // console.log(q.size())
        // console.log(q.isEmpty())
        // console.log(q.toString())
        // console.log(q.front())


        function passGame(name, num) {
            let q = new Queue()
            for (let i = 0; i < name.length; i++) {
                q.enqueue(name[i])
            }
            while (q.size() > 1) {
                for (let j = 0; j < num - 1; j++) {
                    q.enqueue(q.dequeue())
                }
                q.dequeue()
            }
            let res = q.front()
            console.log(q.size())
            console.log(res)
            return name.indexOf(res)
        }

        let res = passGame(['mike', 'lucy', 'join', 'marry', 'bob', 'jason'], 3)
        console.log(res)
    </script>
</body>

</html>